﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace UCL.Powersource.Helpers
{
    [DataContract]
    public class ConfigurationItem<T> : PropertyChangedBase, ILabel
        where T : ILabel
    {
        [DataMember]
        public T ItemToConfigure { get; private set; }

        [IgnoreDataMember]
        public string Label { get { if (ItemToConfigure == null) return "#NULL"; else return ItemToConfigure.Label; } }

        public ConfigurationItem(T itemToConfigure)
        {
            if (itemToConfigure is INotifyPropertyChanged)
            {
                ((INotifyPropertyChanged)itemToConfigure).PropertyChanged += ConfigurationItem_PropertyChanged;
            }
            this.ItemToConfigure = itemToConfigure;
        }

        void ConfigurationItem_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (PropertyExtensions.IsPropertyChanged(e, () => Label)) NotifyOfPropertyChange(() => Label);
        }


        
    }
}
